package com.wac.data.Intercepter;

import com.wac.data.service.UserService;
import com.wac.data.utils.DataListUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class Interceptor implements HandlerInterceptor {

	@Autowired
	private UserService userService;

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		String userId = userService.isUserLogin(new DataListUtil().getCookies(request));
		if (userId == null) {
			response.sendRedirect("/state/user/error");
			return false;
		}
		return true;
	}
}
